/***************************************************************************
 *   Copyright (C) 2008 by Rysiek Kr�l,,,   *
 *   rysiek@Babylon2   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#include "propertydialog.h"

#include <QStyle>
#include <QFileDialog>

/**
* Konstruktor Klasy
*/
PropertyDialog::PropertyDialog(Property *property, QWidget* parent, Qt::WFlags fl)
                : QDialog( parent, fl ), Ui::PropertyDialog()
{
        setupUi(this);
        this->itsProperty = property;
        this->directoryChoseButton->setIcon(this->style()->standardIcon(QStyle::SP_DirOpenIcon));
        this->directoryChoseButton->setText("");
        this->connectSlots();
        this->fillFields();
}

/**
* Destruktor Klasy
*/
PropertyDialog::~PropertyDialog()
{
}

/**
* Slot podpięty do przycisku "cancel"
*/
void PropertyDialog::reject()
{
  QDialog::reject();
}

/**
* Slot obsługujący przycisk "ok"
*/
void PropertyDialog::accept()
{
 this->saveFields();
  QDialog::accept();
}

/**
* Uruchamia okno wyboru katalogu i ustawia zwrócony katalog
*/
void PropertyDialog::choseDirectory()
{
        this->chosedDirectory->setText(QFileDialog::getExistingDirectory(this, tr("Open Directory"), QDir::home().absolutePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
}

/**
* Podłącza sloty
*/
void PropertyDialog::connectSlots()
{
        connect (this->directoryChoseButton, SIGNAL ( clicked() ), this, SLOT ( choseDirectory() ) );
}

/**
* Wypełnia pola formularza
*/
void PropertyDialog::fillFields()
{
        this->chosedDirectory->setText(this->itsProperty->getPictureDir().absolutePath());
        if (this->itsProperty->getShowScalledPictures()){
        	this->showPictureScaledCheckBox->setCheckState(Qt::Checked);
        } else {
        	this->showPictureScaledCheckBox->setCheckState(Qt::Unchecked);
        }
}

/**
* Zpisuje Ustawienia do klasy Property i zapisuje ustawienia na dysku
*/
void PropertyDialog::saveFields()
{
	this->itsProperty->setPictureDir(this->chosedDirectory->text());
	if (this->showPictureScaledCheckBox->checkState() != Qt::Unchecked){
		this->itsProperty->setShowScalledPictures(true);
	} else {
		this->itsProperty->setShowScalledPictures(false);
	}
	this->itsProperty->saveProperty();
}



